package ningbo.file;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.Method;
import java.util.Random;

/**
 * @Author 宁铂
 * @Date 2021/7/27 9:30
 * @Version 1.0
 */
public class TestOut2 {
    public static void main(String[] args) {
        method1();
        method2();
    }

    private static void method1() {
        Writer out = null;
        try {
            out = new FileWriter("F:\\TestFile\\1.txt");

            Random random = new Random(47);
            for (int i = 1; i<= 10 ; i++){

                out.write(random.nextInt(100));

            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void method2() {
        Writer out = null;
        try {
            out = new BufferedWriter(new FileWriter("F:\\TestFile\\1.txt",true));

            Random random = new Random(47);
            for (int i = 1; i<= 10 ; i++){

                out.write(random.nextInt(100));

            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
